package com.polaris.live.im.sfs.processor.impl.system

import com.google.gson.JsonParser
import com.polaris.live.common.util.UserAccountUtils
import com.polaris.live.im.sfs.COMMAND_SUCCESS
import com.polaris.live.im.sfs.core.SmartFoxManager
import com.polaris.live.im.sfs.core.bean.DataArgument
import com.polaris.live.im.sfs.processor.AbstractMessageProcessor
import kotlinx.coroutines.withContext

/**
 * 拓展的账户信息处理
 *
 * @author Created by lucas on 2023/10/23 15:25
 * @since 1.0.0
 */
class ExtAccountMessageProcessor : AbstractMessageProcessor() {

    override fun shouldProcess(type: Int, command: String): Boolean {
        return command == COMMAND_SUCCESS
    }

    override suspend fun handle(type: Int, command: String, argument: DataArgument) {
        val ext = argument.getSfsData()?.getUtfString("ext")
            ?: return

        val extElement = JsonParser.parseString(ext)

        withContext(SmartFoxManager.noticeDispatcher) {
            UserAccountUtils.handleExtAccount(extElement)
        }
    }
}